#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define pell pair<ll,ll>
#define pei pair<int,int>
#define dpe pair<ll,pe>
#define x first
#define y second
const ll maxn=3e5+10,maxmask=(1<<8);
int n,m,a[maxn][10],vt[maxmask];
pei ans;
bool check(int x)
{
for(int i=0;i<(1<<n);i++)
vt[i]=0;
for(int i=1;i<=m;i++)
{
int tmp=0;
for(int j=1;j<=n;j++)
{
if(a[i][j]>=x)
{
tmp+=(1<<(j-1));
}
}
vt[tmp]=i;
}
for(int i=0;i<(1<<n);i++)
{
for(int j=0;j<(1<<n);j++)
{
if((vt[i]&&vt[j])&&((i|j)==(1<<n)-1))
{
ans={vt[i],vt[j]};
return 1;
}
}
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
if(fopen("111.INP","r"))
{
freopen("111.INP","r",stdin);
freopen("111.OUT","w",stdout);
}
cin>>m>>n;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
}
}
int l=0,r=1e9;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid)) l=mid+1;
else r=mid-1;
}
cout<<ans.x<<" "<<ans.y;
}
32. Longest Valid Parentheses | Cutting a material |
Bubble Sort | Number of triangles |
AND path in a binary tree | Factorial equations |
Removal of vertices | Happy segments |
Cyclic shifts | Zoos |
Build a graph | Almost correct bracket sequence |
Count of integers | Differences of the permutations |
Doctor's Secret | Back to School |
I am Easy | Teddy and Tweety |
Partitioning binary strings | Special sets |
Smallest chosen word | Going to office |
Color the boxes | Missing numbers |
Maximum sum | 13 Reasons Why |
Friend's Relationship | Health of a person |
Divisibility | A. Movement |